// pages/duobao/zjRec/zjRec.js
import S_request from '../../../utils/requestService.js';
import CONFIG from '../../../config.js';
import * as utils from '../../../utils/util.js';
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    zjList: [],
    id: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getZJRecord();
  },
  getZJRecord: function() {
    S_request.mine.zjRecord((result) => {
      for (let i = 0; i < result.lists.length; i++) {
        let item = result.lists[i];
        item.open_time = utils.formatTime(item.open_time, 3);
        //pay_status表示类型 0：系统随机 1：分享最多者获得
        if (item.pay_status == 0) {
          item.txt = '系统随机抽取'
        } else {
          item.txt = '邀请最多者获得'
        }
        if (item.jindu == 0) { //查看
          item.btnTitle = '点击领取'
          item.btnStyle = 'background-color:#f77e2e;'
        } else if (item.jindu == 1) { //处理中
          item.btnTitle = '处理中'
          item.btnStyle = 'background-color:#ec0504;'
        } else { //已发放
          item.btnTitle = '已发放'
          item.btnStyle = 'background-color:#999;'
        }
      }
      this.setData({
        zjList: result.lists
      })
    })
  },
  chakan: function(e) {
    let id = e.currentTarget.dataset.id;
    let jindu = e.currentTarget.dataset.jindu;
    if (jindu == 0) { //查看
      let type = e.currentTarget.dataset.type;
      wx.navigateTo({
        url: '../shopExcAddr/shopExcAddr?goodId=' + id + "&type=" + type,
      })
    }
  },
  toDetail: function(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../../JX/detail/detail?id=' + id,
    })
    console.log("detail id==" + id)
  },
  //触摸变小动画
  setShrink: function(e) {
    this.setData({
      id: e.currentTarget.dataset.id,
    });
    let animation1 = wx.createAnimation({
      transformOrigin: "50% 50%",
      duration: 200,
      timingFunction: "ease"
    });
    animation1.scale(0.95).step();
    this.setData({
      animation1: animation1.export()
    });
  },
  //手指离开放大动画
  remShrink: function(e) {
    this.setData({
      id: e.currentTarget.dataset.id,
    });
    let animation1 = wx.createAnimation({
      transformOrigin: "50% 50%",
      duration: 200,
      timingFunction: "ease"
    });
    animation1.scale(1.0).step();
    this.setData({
      animation1: animation1.export()
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getZJRecord();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    wx.showShareMenu({
      withShareTicket: false,
      success: function() {}
    });
    let obj = { 'pagepath': CONFIG.SHARE.path }
    S_request.jx.recordShare("-1", obj);
    return {
      title: CONFIG.SHARE.title,
      path: CONFIG.SHARE.path,
      imageUrl: CONFIG.SHARE.imageUrl,
      success: (res) => { //新版不走回调
        console.log("分享成功")
      }
    }
  },
})